#include "xmlWidget.h"
using namespace xmlWidgetLib;

#include <iostream>
#include <string>
using namespace std;

#include "xmlWidgetEventHandler.h"
#include "logManager.h"
/*
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
*/

void xmlWidget::parseXmlMainWindow(void) throw( string * )
{
	logger << __FUNCTION__ << " Start" << endl;

	TiXmlElement* levelElement = m_XmlRoot->FirstChildElement("level");
	string level("0");
	if(levelElement)
	{
		level = levelElement->GetText();
	}
	if( "0" == level )
	{
		m_Widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	}
	else
	{
		m_Widget = gtk_window_new(GTK_WINDOW_POPUP);
	}
	if( NULL == m_Widget )
	{
		throw new string("Error: can not new gtk window");
	}
	
	const char *title = m_XmlRoot->Attribute("title");
	if( title )
	{
		gtk_window_set_title( GTK_WINDOW(m_Widget),title);
	}

	TiXmlElement* widthElement = m_XmlRoot->FirstChildElement("width");
	gint width = 640;
	if(widthElement)
	{
		const char *text = widthElement->GetText();
		if(text)
		{
			width = atoi(text);
		}
	}
	TiXmlElement* heightElement = m_XmlRoot->FirstChildElement("height");
	gint height = 360;
	if(heightElement)
	{
		const char *text = heightElement->GetText();
		if(text)
		{
			height = atoi(text);
		}
	}
	gtk_widget_set_size_request( m_Widget,width,height);

	g_signal_connect(G_OBJECT(m_Widget), "destroy", G_CALLBACK(MainWindowDestroy_CallBack),(gpointer) this );

	logger << __FUNCTION__ << " Success" << endl;
}

void xmlWidget::parseXmlSubWindow(void) throw( string * )
{
	logger << __FUNCTION__ << " Start" << endl;


	logger << __FUNCTION__ << " Success" << endl;
}
